// 没有写路径的包，默认会从node_modules这个文件导入
const koa = require("koa");
const app = new koa();

// 1、导入路由
const router = require("koa-router")()
const data = require("./data/local")
// 2、新建路由
router.get("/top/playlists",async ctx=>{
    console.log(ctx.request.query);
    var {offset,limit} = ctx.request.query;
    offset = Number(offset);
    limit = Number(limit)
    var result = data.result;
    if(!offset){
        offset = 0;
    }
    if(!limit){
        limit = 5;
    }
    ctx.body={
        code:200,
        data:result.slice(offset,offset+limit),
        total:result.length
    }
})
// 3、配置路由
app.use(router.routes());
app.listen(4000)